/**
 * chinagoods.com
 * Copyright (c) 2020-2024 All Rights Reserved.
 */
package com.ruoyi.common.utils;

import com.alipay.api.AlipayApiException;

import java.nio.charset.StandardCharsets;

/**
 * @author yangpeng
 * Created by on 2024-03-07 10:30
 */
public class UrlHexUtil {
    public static void main(String[] args) throws AlipayApiException {
        // createUrl("11111111111",new BigDecimal(12));
//        getBase64("");
        String url = "www.example.com";

        System.out.println(encode(url));
    }

    public static String encode(String url) {
        String hexString = bytesToHex(url.getBytes(StandardCharsets.UTF_8));
        return hexString;
    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder hexString = new StringBuilder();
        for (byte b : bytes) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) {
                hexString.append('0');
            }
            hexString.append("%");
            hexString.append(hex);
        }
        return hexString.toString();
    }

}